package com.ptswitch.material.pages.bom;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.ptswitch.material.model.material.Bom;
import com.ptswitch.material.pages.base.MaterialBasePage;
import com.ptswitch.material.service.BomService;
import com.ptswitch.material.util.HlogConstants;

public class DeleteBom extends MaterialBasePage {

    @Inject
    private BomService bomSer;

    @OnEvent(value = EventConstants.ACTIVATE)
    Object delete(String id) {
        checkUserIsAdmins();
        Bom bom = bomSer.findById(id);
        getWebUtil().delete(bom.getOrigFile());
        bomSer.delete(bom);
        hlog(HlogConstants.deleteBom, bom);
        return ListBom.class;
    }
}
